﻿#region Entity

using System;
using System.Data;
using System.Data.Common;
using Common;
using Oracle.DataAccess.Client;
using Platform.Configuration;
using Platform.Data;

namespace Entity
{
    [Serializable]
    public class YS_CB_HUIZONGCW
    {
        private string _D_CAOZUORQ;
        private string _I_LEIXING;
        private int _I_M;
        private int _I_Y;
        private string _S_BIANHAO;
        private string _S_BIANHAOGS;
        private string _S_CUOWUXX;
        private string _S_GUANLIKH;
        private string _S_MINGCHENG;
        private string _S_SHUIBIAOBH;
        private string _S_XIUGAIR;
        private string _S_YONGHUBH;

        /// <summary>
        ///     行政编号
        /// </summary>
        public string S_BIANHAO
        {
            get { return _S_BIANHAO; }
            set { _S_BIANHAO = value; }
        }

        /// <summary>
        ///     行政名称
        /// </summary>
        public string S_MINGCHENG
        {
            get { return _S_MINGCHENG; }
            set { _S_MINGCHENG = value; }
        }

        /// <summary>
        ///     管理块号
        /// </summary>
        public string S_GUANLIKH
        {
            get { return _S_GUANLIKH; }
            set { _S_GUANLIKH = value; }
        }

        /// <summary>
        ///     水量年
        /// </summary>
        public int I_Y
        {
            get { return _I_Y; }
            set { _I_Y = value; }
        }

        /// <summary>
        ///     水量月
        /// </summary>
        public int I_M
        {
            get { return _I_M; }
            set { _I_M = value; }
        }

        /// <summary>
        ///     用户编号
        /// </summary>
        public string S_YONGHUBH
        {
            get { return _S_YONGHUBH; }
            set { _S_YONGHUBH = value; }
        }

        /// <summary>
        ///     水表编号
        /// </summary>
        public string S_SHUIBIAOBH
        {
            get { return _S_SHUIBIAOBH; }
            set { _S_SHUIBIAOBH = value; }
        }

        /// <summary>
        ///     操作修改人
        /// </summary>
        public string S_XIUGAIR
        {
            get { return _S_XIUGAIR; }
            set { _S_XIUGAIR = value; }
        }

        /// <summary>
        ///     错误类型
        /// </summary>
        public string I_LEIXING
        {
            get { return _I_LEIXING; }
            set { _I_LEIXING = value; }
        }

        /// <summary>
        ///     错误信息
        /// </summary>
        public string S_CUOWUXX
        {
            get { return _S_CUOWUXX; }
            set { _S_CUOWUXX = value; }
        }

        /// <summary>
        ///     编号公司
        /// </summary>
        public string S_BIANHAOGS
        {
            get { return _S_BIANHAOGS; }
            set { _S_BIANHAOGS = value; }
        }

        /// <summary>
        ///     操作日期
        /// </summary>
        public string D_CAOZUORQ
        {
            get { return _D_CAOZUORQ; }
            set { _D_CAOZUORQ = value; }
        }
    }
}

#endregion

#region EntityProcess

namespace BLL
{
    public abstract class YS_CB_HUIZONGCWProcess
    {
        #region Field

        protected string conn;

        #endregion

        #region Construction

        public YS_CB_HUIZONGCWProcess()
        {
            var connectionEncodeAndDecode = new ConnectionEncodeAndDecode();
            conn = connectionEncodeAndDecode.DecodeBase64(ConfigHelper.PlatformConnString);
            //conn = Platform.Configuration.ConfigHelper.PlatformConnString; 
        }

        #endregion

        /// <summary>
        ///     查错
        /// </summary>
        /// <param name="S_GUANLIKH">管理块号</param>
        /// <param name="IY">水量年</param>
        /// <param name="IM">水量月</param>
        /// <param name="StartMonth">冬灌表起始月</param>
        /// <param name="EndMonth">冬灌表结束月</param>
        /// <param name="Transaction">事务</param>
        /// <returns></returns>
        public DataTable Select_YS_CB_HUIZONGXX(string S_GUANLIKH, int IY, int IM, int StartMonth, int EndMonth,
            DbTransaction Transaction, int type)
        {
            var spName = "P_YS_CB_HUIZONGCW";
            var storedParams = OracleHelperParameterCache.GetSpParameterSet(conn, spName);
            storedParams[0].Value = S_GUANLIKH;
            storedParams[1].Value = IY;
            storedParams[2].Value = IM;
            storedParams[3].Value = StartMonth;
            storedParams[4].Value = EndMonth;
            storedParams[5].Value = type;


            DataSet ds = null;
            if (Transaction == null)
                ds = OracleHelper.ExecuteDataset(conn, CommandType.StoredProcedure, spName, storedParams);
            else
                ds = OracleHelper.ExecuteDataset((OracleTransaction) Transaction, CommandType.StoredProcedure, spName,
                    storedParams);
            if (ds != null && ds.Tables.Count > 0)
                return ds.Tables[0];
            return null;
        }

        public DataTable Select_YS_CB_HUIZONGXXByPage(string S_GUANLIKH, int IY, int IM, int pagesize, int pageindex,
            DbTransaction Transaction)
        {
            var endindex = pagesize * pageindex + pagesize;
            var sqlwehre = "select * from ys_cb_huizongcw where rownum between {0} and {1} ";
            sqlwehre = string.Format(sqlwehre, pagesize * pageindex, endindex);

            DataSet ds = null;
            if (Transaction == null)
                ds = OracleHelper.ExecuteDataset(conn, CommandType.Text, sqlwehre, null);
            else
                ds = OracleHelper.ExecuteDataset((OracleTransaction) Transaction, CommandType.Text, sqlwehre, null);
            if (ds != null && ds.Tables.Count > 0)
                return ds.Tables[0];
            return null;
        }

        /// <summary>
        ///     汇总操作
        /// </summary>
        /// <param name="S_GUANLIKH">管理块编号</param>
        /// <param name="IY">水量年</param>
        /// <param name="IM">水量月</param>
        /// <param name="StartMonth">冬灌开始月</param>
        /// <param name="EndMonth">冬灌终止月</param>
        /// <param name="user">操作人</param>
        /// <param name="Transaction">事务</param>
        /// <returns>表</returns>
        public DataTable Get_YS_CB_HUIZONGTJ(string S_GUANLIKH, int IY, int IM, int StartMonth, int EndMonth,
            string user, DbTransaction Transaction)
        {
            var spName = "P_YS_CB_HUIZONGTJ";
            var storedParams = OracleHelperParameterCache.GetSpParameterSet(conn, spName);
            storedParams[0].Value = S_GUANLIKH;
            storedParams[1].Value = IY;
            storedParams[2].Value = IM;
            storedParams[3].Value = StartMonth;
            storedParams[4].Value = EndMonth;
            storedParams[5].Value = user;


            DataSet ds = null;
            if (Transaction == null)
                ds = OracleHelper.ExecuteDataset(conn, CommandType.StoredProcedure, spName, storedParams);
            else
                ds = OracleHelper.ExecuteDataset((OracleTransaction) Transaction, CommandType.StoredProcedure, spName,
                    storedParams);
            if (ds != null && ds.Tables.Count > 0)
                return ds.Tables[0];
            return null;
        }

        /// <summary>
        ///     开账查错
        /// </summary>
        /// <param name="S_GUANLIKH">管理块号</param>
        /// <param name="IY">水量年</param>
        /// <param name="IM">月</param>
        /// <param name="StartMonth">冬灌表开始月份</param>
        /// <param name="EndMonth">冬灌表结束月份</param>
        /// <param name="user">操作人</param>
        /// <param name="type">类型</param>
        /// <param name="outmsg">代出出参数数字</param>
        /// <param name="errmsg">带出参数字符串</param>
        /// <param name="Transaction">事务</param>
        /// <returns></returns>
        public DataTable Get_YS_CB_KAIZHANGCC(string S_GUANLIKH, int IY, int IM, int StartMonth, int EndMonth,
            string user, int type, out string outmsg, out string errmsg, DbTransaction Transaction)
        {
            var spName = "P_YS_CB_KAIZHANGCC";
            var storedParams = OracleHelperParameterCache.GetSpParameterSet(conn, spName);
            storedParams[0].Value = S_GUANLIKH;
            storedParams[1].Value = IY;
            storedParams[2].Value = IM;
            storedParams[3].Value = StartMonth;
            storedParams[4].Value = EndMonth;
            storedParams[5].Value = type;
            storedParams[6].Value = user;

            storedParams[7].Direction = ParameterDirection.Output;
            storedParams[8].Direction = ParameterDirection.Output;
            DataSet ds = null;
            if (Transaction == null)
                ds = OracleHelper.ExecuteDataset(conn, CommandType.StoredProcedure, spName, storedParams);
            else
                ds = OracleHelper.ExecuteDataset((OracleTransaction) Transaction, CommandType.StoredProcedure, spName,
                    storedParams);
            outmsg = storedParams[7].Value.ToString();
            errmsg = storedParams[8].Value.ToString();
            if (ds != null && ds.Tables.Count > 0)
                return ds.Tables[0];
            return null;
        }

        public DataTable Get_YS_CB_KAIZHANG(string S_GUANLIKH, int IY, int IM, int StartMonth, int EndMonth,
            string user, int type, DbTransaction Transaction)
        {
            var spName = "P_YS_CB_KAIZHANG";
            var storedParams = OracleHelperParameterCache.GetSpParameterSet(conn, spName);
            storedParams[0].Value = S_GUANLIKH;
            storedParams[1].Value = IY;
            storedParams[2].Value = IM;
            storedParams[3].Value = StartMonth;
            storedParams[4].Value = EndMonth;
            storedParams[5].Value = type;
            storedParams[6].Value = user;

            DataSet ds = null;
            if (Transaction == null)
                ds = OracleHelper.ExecuteDataset(conn, CommandType.StoredProcedure, spName, storedParams);
            else
                ds = OracleHelper.ExecuteDataset((OracleTransaction) Transaction, CommandType.StoredProcedure, spName,
                    storedParams);

            if (ds != null && ds.Tables.Count > 0)
                return ds.Tables[0];
            return null;
        }

        public DataTable YS_CB_GONGSIBM(string V_GONGSIMC, out string V_TABLENAME, DbTransaction Transaction)
        {
            var spName = "YS_CB_GONGSIBM";
            var storedParams = OracleHelperParameterCache.GetSpParameterSet(conn, spName);
            storedParams[0].Value = V_GONGSIMC;
            storedParams[1].Direction = ParameterDirection.Output;


            DataSet ds = null;
            if (Transaction == null)
                ds = OracleHelper.ExecuteDataset(conn, CommandType.StoredProcedure, spName, storedParams);
            else
                ds = OracleHelper.ExecuteDataset((OracleTransaction) Transaction, CommandType.StoredProcedure, spName,
                    storedParams);
            V_TABLENAME = storedParams[1].Value.ToString();
            if (ds != null && ds.Tables.Count > 0)
                return ds.Tables[0];
            return null;
        }
    }
}

#endregion